#include "base/callback.h"
#include "gtest/gtest.h"

int global_var = 5;

void MyFunction0() {
  global_var = 3;
}

TEST(CallbackTest, TestNewCallback0) {
  Closure* c = NewCallback(&MyFunction0);
  c->Run();
  EXPECT_EQ(3, global_var);
}

void MyFunction1(int a) {
  global_var = a;
}

TEST(CallbackTest, TestNewCallback1) {
  Closure* c = NewCallback(&MyFunction1, 100);
  c->Run();
  EXPECT_EQ(100, global_var);
}

class A {
 public:
  void SetVar(int i) { global_var = i; }
};

TEST(CallbackTest, TestNewCallbackClass) {
  A a;
  Closure* c = NewCallback(&a, &A::SetVar, 200);
  c->Run();
  EXPECT_EQ(200, global_var);
}
